<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>密码修改</title>
    <meta name="viewport" content="initial-scale=1, maximum-scale=1">
    <link rel="shortcut icon" href="/static/favicon.ico">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="stylesheet" href="/static/css/sm.min.css">
    <link rel="stylesheet" href="/static/css/sm-extend.min.css">
    <style>
        .list-block .item-title.label {
            width: 15%;
        }
    </style>
</head>

<body>

<header class="bar bar-nav">
    <a class="icon icon-left pull-left" href="javascript:history.back(-1)"></a>
    <h1 class="title">密码修改</h1>
</header>

<div class="content">
    <div class="list-block">
        <input type="hidden" name="data">
        <ul>
            <li>
                <div class="item-content">
                    <div class="item-media"><i class="icon icon-form-name"></i></div>
                    <div class="item-inner">
                        <div class="item-title label"><img src="/static/img/phone.png" style="width: 1.3rem"></div>
                        <div class="item-input">
                            <input type="number" placeholder="请输入绑定的电话号码" name="phone" onblur="checkPhone()">
                        </div>
                    </div>
                </div>
            </li>
            <li>
                <div class="item-content">
                    <div class="item-media"><i class="icon icon-form-password"></i></div>
                    <div class="item-inner">
                        <div class="item-title label"><img src="/static/img/password.png" style="width: 1.3rem"></div>
                        <div class="item-input">
                            <input type="password" placeholder="请输入新密码" class="" name="passwordNew">
                        </div>
                    </div>
                </div>
            </li>
        </ul>
    </div>
    <div class="content-block">
        <p>
            <a href="#" onclick="updatePwd()" class="button button-big button-fill">确认修改 </a>
        </p>
    </div>
</div>

<script type='text/javascript' src='/static/lib/zepto/zepto.min.js' charset='utf-8'></script>
<script type='text/javascript' src='/static/js/sm.min.js' charset='utf-8'></script>
<script type='text/javascript' src='/static/js/sm-extend.min.js' charset='utf-8'></script>

<script>
    //验证电话号码
    function checkPhone() {
        var phone = $("input[name='phone']").val().trim();
        $.ajax({
            type : "post",
            url  : "/sys/user/updatePwdByPhone",
            data : {
              "phone":phone
            },
            dataType : "json",
            success : function (re) {
                var result = re;
                if (result.status === 0){
                    $("input[name= 'data']").val(result.data);
                } else {
                    $.toast(result.msg);
                }
            }
        })
    };
    function updatePwd() {
        var passwordNew = $("input[name = 'passwordNew']").val().trim();
        var data = $("input[name = 'data']").val().trim();
        $.ajax({
            type : "post",
            url  : "/sys/user/updatePwd",
            dataType : "json",
            data : {
                "token" : data,
                "passwordNew" : passwordNew
            },
            success : function (re) {
                var result = re;
                if (result.status === 0){
                    alert(result.msg);
                    window.location.href = '/page/loginUI'
                }else{
                    $.toast(result.msg);
                }
            }
        })
    }
</script>
</body>

</html>